import {
  IsEmail,
  IsEnum,
  IsNotEmpty,
  IsOptional,
  IsString,
  Length,
} from 'class-validator';
import {
  AccountErrorKey,
  VerifyMethod,
  VerifyType,
} from '../../../common/constants/user.constant';
import { i18nValidationMessage } from 'nestjs-i18n';
import { CheckPasswordStrength } from '../../../common/decorators/custom-class-validator.decorator';

export class RegisterDto {
  @IsNotEmpty({ message: AccountErrorKey.EMAIL_NOT_EMPTY })
  @IsEmail({}, { message: AccountErrorKey.EMAIL_FORMAT_ERROR })
  email: string;

  @IsNotEmpty({ message: AccountErrorKey.USERNAME_NOT_EMPTY })
  @Length(2, 10, {
    message: i18nValidationMessage<Record<string, string>>(
      AccountErrorKey.USERNAME_FORMAT_ERROR,
      {
        min: 2,
        max: 10,
      },
    ),
  })
  username: string;

  @IsNotEmpty({ message: AccountErrorKey.PASSWORD_NOT_EMPTY })
  @IsString()
  @CheckPasswordStrength(4)
  password: string;
}

export class LoginDto {
  @IsNotEmpty({ message: AccountErrorKey.EMAIL_NOT_EMPTY })
  @IsEmail({}, { message: AccountErrorKey.EMAIL_FORMAT_ERROR })
  email: string;

  @IsNotEmpty({ message: AccountErrorKey.PASSWORD_NOT_EMPTY })
  password: string;
}

export class RedactDto {
  @IsOptional()
  @IsNotEmpty({ message: AccountErrorKey.USERNAME_NOT_EMPTY })
  @Length(2, 10, {
    message: i18nValidationMessage<Record<string, string>>(
      AccountErrorKey.USERNAME_FORMAT_ERROR,
      {
        min: 2,
        max: 10,
      },
    ),
  })
  username?: string;
}

export class RemoveDto {
  @IsNotEmpty({ message: AccountErrorKey.PASSWORD_NOT_EMPTY })
  password: string;
}

export class SendVerifyCodeDto {
  @IsEnum(VerifyMethod)
  method: VerifyMethod;

  @IsEnum(VerifyType)
  type: VerifyType;

  @IsEmail({}, { message: AccountErrorKey.EMAIL_FORMAT_ERROR })
  @IsOptional()
  email?: string;
}
